<!--
 * new page
 * @author: liuxin
 * @since: 2024-08-16
 * delete_admin.vue
-->
<template>
    <el-dialog v-model="dialogFormVisible" title='删除文件' width="30%" center>
        <span>请谨慎操作，您确定要真正删除这个文件吗？</span>
        <template #footer>
            <span class="dialog-footer">
                <el-button type="primary" @click="operationFilesFn">删除</el-button>
            </span>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import { ref, onBeforeUnmount } from "vue"
import { bus } from "@/utils/mitt.js"
import { deleteFile } from '@/api/file'
import { ElMessage } from 'element-plus'
const title = ref()
// 消息ID
const fileid = ref()
const filename = ref()

bus.on('deleteFile', (row: any) => {
    title.value = '删除文件'
    fileid.value = row.id
    filename.value = row.file_name

})
const emit = defineEmits(['success'])
// 删除产品
const operationFilesFn = async () => {
    if (title.value == '删除文件') {
        console.log(fileid.value);
        const res = await deleteFile(fileid.value, filename.value)
        console.log(res);
        if (res.status == 0) {
            ElMessage({
                message: '删除文件成功',
                type: 'success'
            })
            emit('success')
            dialogFormVisible.value = false
        } else {
            ElMessage.error('删除文件失败')
            dialogFormVisible.value = false
        }
    }
}


// 弹窗开关

const dialogFormVisible = ref(false)
// 打开编辑管理员弹窗
const open = () => {
    dialogFormVisible.value = true
}
defineExpose({
    open
})

// 取消订阅/监听
onBeforeUnmount(() => {
    bus.all.clear()
})
</script>

<style scoped lang="scss"></style>